use axum_app_common::database;
use deadpool_redis::{
    redis::{cmd, AsyncCommands},
    Config, ConnectionAddr, ConnectionInfo, PoolConfig, RedisConnectionInfo, Runtime,
};

#[tokio::test]
async fn test_deadpool() {
    let pool = database::redis_conn_pool_from_env().unwrap();

    {
        let mut conn = pool.get().await.unwrap();
        cmd("SET")
            .arg(&["deadpool/test_key", "42"])
            .query_async::<_, ()>(&mut conn)
            .await
            .unwrap();

        let _: () = conn.set_ex("my_key", "hhjjjkkk", 10u64).await.unwrap();
    }
    {
        let mut conn = pool.get().await.unwrap();
        let res = cmd("GET")
            .arg(&["deadpool/test_key222"])
            .query_async::<_, Option<String>>(&mut conn)
            .await;
        println!("res={:?}", res);
        match res {
            Ok(_) => {}
            Err(err) => {
                println!("err code:{:?}", err.code());
                println!("err category:{:?}", err.category());
            }
        }
    }
}
